/**
 * qq:https://q.qq.com/wiki/
 * tt:https://microapp.bytedance.com/docs/zh-CN/mini-app/develop/guide/start/introduction/
 * wx:https://developers.weixin.qq.com/minigame/dev/guide/
 * vivo:https://minigame.vivo.com.cn/documents/#/
 * swan:https://smartprogram.baidu.com/docs/introduction/enter_application/
 * oppo:https://activity-cdo.heytapimage.com/cdo-activity/static/201810/26/quickgame/documentation/#/README
 */

export enum SDKDir {
    RIGHT_MID = 0,
    RIGHT_UP = 1,
    RIGHT_BOTTOM = 2,
    LEFT_MID = 3,
    LEFT_UP = 4,
    LEFT_BOTTOM = 5,
    UP_MID = 6,
    BOTTOM_MID = 7,
    MID
}

//广告名称
export const ADName = {
    banner: 'banner',//bander 广告
    reward: 'reward',//激励视频
    insert: 'insert',//插屏广告
    native: 'native',//原生广告
    appbox: 'appbox',//盒子广告
    portal: 'portal',//九宫格广告 oppo
    grid: 'grid', //格子广告
    block: 'block',//积木广告
    shareTitle: 'shareTitle',//分享标题
    shareImage: 'shareImage',//分享图片
    imageUrlId: 'imageUrlId',
    share: 'share',
    appid: 'appid',
}

export const FileEncoding = {
    UTF8: 'utf8',
    BINARY: 'binary'
}

export enum SDKState {
    FAIL,
    SUCCESS,
    LOADING,
    CLOSE,
    OPEN,
}


export type ResultCallback = (r: SDKState) => void;
export type DataCallback = (r: SDKState, data: any) => void;

export function isFunction(property: any) {
    return property && typeof (property) == 'function'
}

export type ShareInfo = {
    shareTitle: string,
    shareImage: string,
    imageUrlId: string
}
/**
 * name： 广告名称 如 banner
 * ids:广告id列表
 * version api版本
 * isMultiple：是否支持多个广告实例
 */
export type ADType = { name: string, ids: string[], version?: string, isMultiple?: boolean }

export type ShareType = { shares: ShareInfo[], version?: string }

export type SDKInfo = {
    name: string,
    ads: ADType[],
    share?: ShareType

}
export const QG = 'qg'
//平台名称
export const PlatName = {
    DEV: 'dev',
    WX: 'wx',
    QQ: 'qq',
    TT: 'tt',
    KS: 'ks',
    OPPO: 'oppo',
    VIVO: 'vivo',
    SWAN: 'swan',//百度
    F399: 'h5api',
    COCOS: 'AdSDK',
}
//因为SDKNative是一直存在的，所以要放到最后一个找。
export const SDK_NAMES: string[] = [PlatName.KS, PlatName.QQ, PlatName.TT, PlatName.WX, QG, PlatName.SWAN, PlatName.F399, PlatName.COCOS]

export function getSDK() {
    //负责的底层适配
    if (window['sdk']) {
        return window['sdk']
    }

    //简单的底层适配
    if (window['sly']) {
        return window['sly'].getSDK();
    }

    //无适配
    for (let index = 0; index < SDK_NAMES.length; index++) {
        const element: any = SDK_NAMES[index];
        if (window[element]) {
            return window[element]
        }
    }
    return null;
}